//
//  SpendFunkAppDelegate.m
//  SpendFunk
//
//  Created by bm on 4/18/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SpendFunkAppDelegate.h"
#import "Global.h"

SpendFunkAppDelegate* g_AppDelegate;

@implementation SpendFunkAppDelegate

@synthesize window;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{    
    
    // Override point for customization after application launch.
	g_AppDelegate = self;
	
	m_pHomeViewCtrl = [[HomeViewController alloc] init];
	[self.window addSubview:m_pHomeViewCtrl.view];
	//m_pMainViewCtrl = [[MainViewController alloc] init];
//	[self.window addSubview:m_pMainViewCtrl.view];
	[self.window makeKeyAndVisible];
    //[m_pHomeViewCtrl release];
	return YES;
}


-(void)openLogin
{
	if(!m_pLoginViewCtrl){
		m_pLoginViewCtrl = [[LoginViewController alloc] init];
	}
	m_pHomeViewCtrl.view.hidden = YES;
	[m_pLoginViewCtrl setKeyBroadActive];
	[window addSubview:m_pLoginViewCtrl.view];
	animateView(window, kCATransitionPush, kCATransitionFromRight, 0.3);
}
-(void)openSignup
{
	if (!m_pSignupViewCtrl) {
		m_pSignupViewCtrl = [[SignupViewController alloc] init];
	}
	[m_pSignupViewCtrl setUpdateAccount:FALSE];
	m_pHomeViewCtrl.view.hidden =YES;
	[m_pSignupViewCtrl setKeyBroadActive];
	[window addSubview:m_pSignupViewCtrl.view];
	animateView(window, kCATransitionPush, kCATransitionFromRight, 0.3);
}

-(void)openUpdateView{
	if (!m_pSignupViewCtrl) {
		m_pSignupViewCtrl = [[SignupViewController alloc] init];
	}
	[m_pSignupViewCtrl setUpdateAccount:TRUE];
	m_pHomeViewCtrl.view.hidden =YES;
	[m_pSignupViewCtrl setKeyBroadActive];
	[window addSubview:m_pSignupViewCtrl.view];
	animateView(window, kCATransitionPush, kCATransitionFromRight, 0.3);
}

-(void)goBackHome:(UIView *)view
{
	m_pHomeViewCtrl.view.hidden =NO;
	animateView(window, kCATransitionPush, kCATransitionFromLeft, 0.3);
	[view removeFromSuperview];
}


-(void)openFeaturedMembersWithMembers:(NSArray *)members{
	if(!m_pMainViewCtrl){
		m_pMainViewCtrl = [[MainViewController alloc] init];
	}
	[window addSubview:m_pMainViewCtrl.view];
	animateView(window, kCATransitionPush, kCATransitionFromRight, 0.3);
	[m_pMainViewCtrl displayFeaturedMemberWithMembers:members];
}

-(void)openFindFriendsByView:(UIView *)view{
	if(!m_pFindFriendCtrl){
		m_pFindFriendCtrl = [[FindFriendsViewController alloc] init];
	}
	if((LoginViewController *)view == m_pLoginViewCtrl) {
		[m_pLoginViewCtrl.view removeFromSuperview];
	}
	if((SignupViewController *)view == m_pSignupViewCtrl) { 
		[m_pSignupViewCtrl.view removeFromSuperview];
	}
	
	[window addSubview:m_pFindFriendCtrl.view];
	animateView(window, kCATransitionPush, kCATransitionFromRight, 0.3);
}

-(void)openFindFriends{
	if(!m_pFindFriendCtrl){
		m_pFindFriendCtrl = [[FindFriendsViewController alloc] init];
	}
	
	[window addSubview:m_pFindFriendCtrl.view];
	animateView(window, kCATransitionPush, kCATransitionFromLeft, 0.3);
}

-(void)openUserProfile:(NSDictionary *)userProfile{// se truyen dictionary chua thong tin user dc click o ben feed nhe :D
	[m_pMainViewCtrl openUserProfile:[userProfile retain]];
}

-(void)openLocationView{
	[m_pMainViewCtrl openLocationView];
	
}
// comment
- (void)openCommentView:(NSString*)spendID{
	[m_pMainViewCtrl openCommentView:spendID];
}
-(void)openLocationViewwithFS_ID:(NSString*)fsquareID gLat:(NSString*)gLat gLong:(NSString*)gLong aMount:(NSString*)amount Address:(NSString*)Address City:(NSString*)city{
	[m_pMainViewCtrl openLocationViewwithFS_ID:fsquareID gLat:gLat gLong:gLong aMount:amount Address:Address City:city];
}
-(void)openBadgesView{
	[m_pMainViewCtrl openBadgesView];
}

-(void)openHighView{
	[m_pMainViewCtrl openHighView];
}

-(void)openFeedView{
	[m_pMainViewCtrl openFeedView];
}

-(void)onClickToPost2{
	[m_pMainViewCtrl onClickToPost2];
}

-(void)backToPost1{
	[m_pMainViewCtrl backToPost1];
}
- (void)openPriceView{
	[m_pMainViewCtrl openPriceView];
}

- (void)openWhereViewWithArrPlaces:(NSArray*)arrPlaces{
	[m_pMainViewCtrl openWhereViewWithArrPaces:arrPlaces];
}
-(void)openCateWithArrCate:(NSArray*)arrCate{
	[m_pMainViewCtrl openCateWithArrCate:arrCate];
}
// Search for user
-(void)openSearchforUsers{
	if (!m_pSearchUsers) {
		m_pSearchUsers = [[SearchUsersViewController alloc] init];
	}
	[window addSubview:m_pSearchUsers.view];
	animateView(window, kCATransitionPush, kCATransitionFromRight, 0.3);
}
//NTQUAN
-(void)openListContact
{
	if(!m_pInviteFriendsCtrl){
		m_pInviteFriendsCtrl = [[InviteFriendsViewController alloc] init];
	}
    
	[window addSubview:m_pInviteFriendsCtrl.view];
	animateView(window, kCATransitionPush, kCATransitionFromRight, 0.3);
}

-(void)openDetailContact
{
	if(m_pContactDetailCtrl)
    {
        [m_pContactDetailCtrl release];
        m_pContactDetailCtrl = nil;		
	}
    m_pContactDetailCtrl = [[ContactDetailViewController alloc] init];
    
	[window addSubview:m_pContactDetailCtrl.view];
	animateView(window, kCATransitionPush, kCATransitionFromRight, 0.3);
}
- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}


- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}


- (void)dealloc {
    [window release];
    [super dealloc];
}


@end
